import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    num: -1,
    arr: [
      {
        pname: "联想笔记本电脑",
        id: 1,
        uptDate: new Date(),
        price: 6000,
        count: 50,
        user: "张三",
        isShow: false
      },
      {
        pname: "宏基笔记本电脑",
        id: 2,
        uptDate: new Date(),
        price: 8000,
        count: 30,
        user: "里斯",
        isShow: false
      },
    ],
  },
  getters: {
  },
  mutations: {
    add(state, payload) {
      console.log(state.num);
      if (state.num == -1) {
        state.arr.push(payload);

      }
      else {
        state.arr.splice(state.num, 1, payload);
        state.num = -1
      }
    },
    dels(state, ind) {
      state.arr.splice(ind, 1)
    },
    adds(state, payload) {
      state.num = payload;
    },
    numnot(state) {
      state.num = -1
    }
  },
  actions: {
  },
  modules: {
  }
})
